﻿using System;

namespace IupNET
{
    //this class implements the many common prperties between ComboList and Text
    public class EditBase:Control
    {
        internal EditBase(IntPtr cobj)
            : base(cobj)
        {

        }

        public void Append(string txt)
        {
            SetAttribute("APPEND", txt);
        }

        public Point2i Caret
        {
            get
            {
                return Convert.StringToPoint(GetAttribute("CARET"));
            }
            set
            {
                SetAttribute("CARET", Convert.PointToString(value, ":"));
            }
        }


        public int CaretPos
        {
            get
            {
                return Convert.StringToInt(GetAttribute("CARETPOS"));
            }
            set
            {
                SetAttribute("CARETPOS", value.ToString());
            }
        }

        public void Cut()
        {
            SetAttribute("CLIPBOARD", "CUT");
        }

        public void Copy()
        {
            SetAttribute("CLIPBOARD", "COPY");
        }

        public void Paste()
        {
            SetAttribute("CLIPBOARD", "PASTE");
        }

        public void Insert(string txt)
        {
            SetAttribute("INSERT", txt);
        }

        public Size2i Padding
        {
            get
            {
                return Convert.StringToSize(GetAttribute("PADDING"));
            }
            set
            {
                SetAttribute("PADDING", Convert.SizeToString(value));
            }
        }

        public string Mask
        {
            get
            {
                return GetAttribute("MASK");
            }
            set
            {
                SetAttribute("MASK", value);
            }
        }

        public int MaxLength
        {
            get
            {
                return Convert.StringToInt(GetAttribute("NC"));
            }
            set
            {
                SetAttribute("NC", value.ToString());
            }
        }

        public bool ReadOnly
        {
            get
            {
                return GetAttribute("READONLY") == "YES";
            }
            set
            {
                SetAttribute("READONLY", value ? "YES" : "NO");
            }
        }

        public string SelectedText
        {
            get
            {
                return GetAttribute("SELECTEDTEXT");
            }
            set
            {
                SetAttribute("SELECTEDTEXT", value);
            }
        }

        public string Selection
        { //TODO: implement better handleing of this, and support ALL and NONE options to
            get
            {
                return GetAttribute("SELECTION");
            }
            set
            {
                SetAttribute("SELECTION", value);
            }
        }

        public void ScrollTo(Point2i pos)
        {
            SetAttribute("SCROLLTO", Convert.PointToString(pos, ":"));
        }

        public EventCallback ButtonCB
        {
            get
            {
                return CBHandler.Fetch("BUTTON_CB");
            }
            set
            {
                CBHandler.Set("BUTTON_CB", value);
            }
        }

        public EventCallback CaretCB
        {
            get
            {
                return CBHandler.Fetch("CARET_CB");

            }
            set
            {
                CBHandler.Set("CARET_CB", value);
            }
        }

        public EventCallback DropFilesCB
        {
            get
            {
                return CBHandler.Fetch("DROPFILES_CB");
            }
            set
            {
                CBHandler.Set("DROPFILES_CB", value);
            }
        }





    }
}
